package com.jeff.huawei.practice;

import java.util.*;

public class Test3 {
    private static int n, m, k;
    private static char[][] map;
    private static boolean[][] visited;
    private static int[] dx = {0, 1, 0, -1};
    private static int[] dy = {1, 0, -1, 0};

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        k = scanner.nextInt();
        scanner.nextLine(); 
        
        map = new char[n][m];
        visited = new boolean[n][m];
        
        for (int i = 0; i < n; i++) {
            map[i] = scanner.nextLine().toCharArray();
        }
        
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (!visited[i][j] && (map[i][j] == '.' || map[i][j] == 'E')) {
                    int enemies = dfs(i, j);
                    if (enemies < k) {
                        count++;
                    }
                }
            }
        }
        
        System.out.println(count);
    }
    
    private static int dfs(int x, int y) {
        Stack<int[]> stack = new Stack<>();
        stack.push(new int[]{x, y});
        visited[x][y] = true;
        int enemyCount = 0;
        
        while (!stack.isEmpty()) {
            int[] current = stack.pop();
            x = current[0];
            y = current[1];
            
            if (map[x][y] == 'E') {
                enemyCount++;
            }
            
            for (int d = 0; d < 4; d++) {
                int nx = x + dx[d];
                int ny = y + dy[d];
                if (nx >= 0 && nx < n && ny >= 0 && ny < m && !visited[nx][ny] && map[nx][ny] != '#') {
                    visited[nx][ny] = true;
                    stack.push(new int[]{nx, ny});
                }
            }
        }
        
        return enemyCount;
    }
}
